package  src
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author Luiz Felipe de S. R.
	 */
	public class Game extends MovieClip
	{
		private var scene : String;
		private var intro : Intro;
		public var level : Level;
		private var menu : Menu;
		
		private var controle : Boolean = true;
		private var cont : int = 0;
		
		private var alphaSPD : Number = 0.01;
		
		
		
		public function Game() 
		{
			init();
		}
		
		private function init():void
		{
			scene = "LEVEL";
			canvas();
			
			this.addEventListener(Event.ENTER_FRAME, update, false, 0, true);
		}
		
		private function canvas():void
		{
			trash();
			
			switch(scene)
			{
				case "INTRO":
					intro = new Intro();
					intro.alpha = 0;
					this.addChild(intro);
					break;
					
				case "MENU":
					menu = new Menu();
					menu.alpha = 0;
					this.addChild(menu);
					menu._start.addEventListener(MouseEvent.CLICK, startLevel);
					break;
					
				case "LEVEL":
					level = new Level();
					this.addChild(level);
					break;
					
				case "GAMEOVER":
					
					break;
			}
		}
		
		private function update(e:Event):void
		{
			if (intro != null)
			{
				if (controle == true && intro.alpha < 1)
				{
					intro.alpha += alphaSPD;
				}
				
				if (intro.alpha >= 1 && controle == true)
				{
					cont++;
					if (cont >= 60)
					{
						controle = false;
						cont = 0;
					}
				}
				
				if (controle == false && intro.alpha > 0)
				{
					intro.alpha -= alphaSPD;
				}
				
				if (intro.alpha <= 0 && controle == false)
				{
					scene = "MENU";
					canvas();
					controle = true;
				}
			}
			
			if (menu != null)
			{
				if (controle == true && menu.alpha < 1)
				{
					menu.alpha += alphaSPD;
				}
				
				if (controle == false && menu.alpha > 0)
				{
					menu.alpha -= alphaSPD;
				}
				
				if (menu.alpha <= 0 && controle == false)
				{
					scene = "LEVEL";
					canvas();
					controle = true;
				}
			}
			
		}
		
		private function startLevel(e:MouseEvent):void
		{
			controle = false;
		}
		
		private function trash():void
		{
			if (intro != null)
			{
				this.removeChild(intro);
				intro = null;
			}
			if (menu != null)
			{
				menu._start.removeEventListener(MouseEvent.CLICK, startLevel);
				this.removeChild(menu);
				menu = null;
			}
			
		}
		
	}

}





